﻿import ctypes
import threading
from core import coreTest
from multiprocessing import Process


class DataSource(object):
    so=ctypes.CDLL('./lib/libpcap7.so')
    #so=coreTest.exTest()
    #进行初始化操作
    def __init__(self):
        self.p = None
        self.p1 = None

    '''
    获取必要的数据
        num 频率刷新次数
        cid ChannelID
        dst1 MAC的第1段
        dst2 MAC的第2段
        dst3 MAC的第3段
        si   信号强度
    '''
    def getData(self):
        num = self.so.getNum()
        # dst1 = '43'
        # dst2 = '41'
        # dst3 = '43'
        dst1 = str(hex(self.so.getDst1()))[2:]
        dst2 = str(hex(self.so.getDst2()))[2:]
        dst3 = str(hex(self.so.getDst3()))[2:]
        si = 0 - int(self.so.getSi())
        cid = self.so.getChannelID()
        return [num,dst1,dst2,
                dst3,si,cid]

    def start(self):
        self.p =coreThread(self.so.capturePack)
        self.p.start()
        print('p线程创建')
        self.p1 = coreThread(self.so.setChannel)
        self.p1.start()
        print('p1线程创建')





    def stop(self):
        self.so.exit0()


class coreThread(threading.Thread):
    def __init__(self,ff):
        threading.Thread.__init__(self)
        self.ff = ff

    def run(self):
        self.ff()